package org.framework.edge.builder.application.impl;

import jakarta.annotation.Resource;
import org.framework.edge.builder.application.DockerBuildModuleApplication;
import org.framework.edge.builder.application.assembler.DockerBuildModuleDTOAssembler;
import org.framework.edge.builder.application.command.docker.build.module.*;
import org.framework.edge.builder.application.dto.DockerBuildModuleDTO;
import org.framework.edge.builder.domain.model.docker.builder.module.DockerBuildModule;
import org.framework.edge.builder.domain.model.docker.builder.module.DockerBuildModuleRepository;
import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.web.response.Result;

import java.util.List;
import java.util.stream.Collectors;
/**
 * describe 打包模块 
 *
 * @author Jia wei Wu
 * @date 2024/08/13 07:39 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl 
 **/
@LazyApplication
public class DockerBuildModuleApplicationImpl implements DockerBuildModuleApplication {

    @Resource
    DockerBuildModuleRepository dockerBuildModuleRepository;
    /**
     * describe 新增打包模块
     *
     * @param dockerBuildModuleStoryCommand 新增打包模块     
     * @return {@link Result<DockerBuildModule>} 打包模块新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModule> story(DockerBuildModuleStoryCommand dockerBuildModuleStoryCommand) {
        DockerBuildModule dockerBuildModule = DockerBuildModuleDTOAssembler.INSTANCE.toDockerBuildModule(dockerBuildModuleStoryCommand);
        return dockerBuildModuleRepository.story(dockerBuildModule);
    }
    /**
     * describe 批量新增打包模块
     *
     * @param dockerBuildModuleStoryCommandList 批量新增打包模块     
     * @return {@link Result<List<DockerBuildModule>>} 打包模块新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<List<DockerBuildModule>> batchStory(List<DockerBuildModuleStoryCommand> dockerBuildModuleStoryCommandList) {
        List<DockerBuildModule> dockerBuildModuleList = dockerBuildModuleStoryCommandList.stream().map( DockerBuildModuleDTOAssembler.INSTANCE::toDockerBuildModule).collect(Collectors.toList());
        return dockerBuildModuleRepository.batchStory(dockerBuildModuleList);
    }
    /**
     * describe 更新打包模块
     *
     * @param dockerBuildModuleUpdateCommand 更新打包模块     
     * @return {@link Result<DockerBuildModule>} 打包模块领域对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModule> updateOne(DockerBuildModuleUpdateCommand dockerBuildModuleUpdateCommand) {
        DockerBuildModule dockerBuildModule = DockerBuildModuleDTOAssembler.INSTANCE.toDockerBuildModule(dockerBuildModuleUpdateCommand);
        return dockerBuildModuleRepository.story(dockerBuildModule);
    }

    /**
     * describe 查询单个打包模块
     *
     * @param dockerBuildModuleQueryOneCommand 查询单个打包模块     
     * @return {@link Result<DockerBuildModuleDTO>} 打包模块DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModuleDTO> findOne(DockerBuildModuleQueryOneCommand dockerBuildModuleQueryOneCommand) {
        DockerBuildModule dockerBuildModule = DockerBuildModuleDTOAssembler.INSTANCE.toDockerBuildModule(dockerBuildModuleQueryOneCommand);
        return dockerBuildModuleRepository.findOne(dockerBuildModule).convert(DockerBuildModuleDTOAssembler.INSTANCE::fromDockerBuildModule);
    }

    /**
     * describe 查询多个打包模块
     *
     * @param dockerBuildModuleQueryListCommand 查询多个打包模块     
     * @return {@link Result<List<DockerBuildModuleDTO>>} 打包模块DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<List<DockerBuildModuleDTO>> findList(DockerBuildModuleQueryListCommand dockerBuildModuleQueryListCommand) {
        DockerBuildModule dockerBuildModule = DockerBuildModuleDTOAssembler.INSTANCE.toDockerBuildModule(dockerBuildModuleQueryListCommand);
        return dockerBuildModuleRepository.findList(dockerBuildModule)        .convert(dockerBuildModules -> dockerBuildModules.stream().map(DockerBuildModuleDTOAssembler.INSTANCE::fromDockerBuildModule).collect(Collectors.toList())) ;
    }

    /**
     * describe 分页查询多个打包模块
     *
     * @param dockerBuildModuleQueryListCommand 分页查询多个打包模块     
     * @return {@link Result<LazyPage<DockerBuildModuleDTO>>} 分页打包模块DTO对象     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<LazyPage<DockerBuildModuleDTO>> findPage(int size,int current,DockerBuildModuleQueryListCommand dockerBuildModuleQueryListCommand) {
        DockerBuildModule dockerBuildModule = DockerBuildModuleDTOAssembler.INSTANCE.toDockerBuildModule(dockerBuildModuleQueryListCommand);
        return dockerBuildModuleRepository.findPage(size,current,dockerBuildModule)        .convert(page -> page.convert(DockerBuildModuleDTOAssembler.INSTANCE::fromDockerBuildModule))            ;
    }

    /**
     * describe 删除打包模块
     *
     * @param dockerBuildModuleRemoveCommand 删除打包模块     
     * @return {@link Result<DockerBuildModule>} 打包模块     
     
     * @author Jia wei Wu
     * @date 2024/08/13 07:39 晚上
     **/

    @Override
    public Result<DockerBuildModule> remove(DockerBuildModuleRemoveCommand dockerBuildModuleRemoveCommand) {
     DockerBuildModule dockerBuildModule = DockerBuildModuleDTOAssembler.INSTANCE.toDockerBuildModule(dockerBuildModuleRemoveCommand);
     return dockerBuildModuleRepository.remove(dockerBuildModule);
    }

}